package com.ss.android.article.base.utils.b;

import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.view.MotionEvent;
import android.widget.TextView;

public final class d extends LinkMovementMethod {
    private e a;

    public d() {

    }

    private static e a(TextView arg3, Spannable arg4, MotionEvent arg5) {
        Object v0_2;
        int v0 = ((int)arg5.getX());
        int v1 = ((int)arg5.getY());
        v0 -= arg3.getTotalPaddingLeft();
        v1 -= arg3.getTotalPaddingTop();
        v0 += arg3.getScrollX();
        v1 += arg3.getScrollY();
        Layout v2 = arg3.getLayout();
        v0 = v2.getOffsetForHorizontal(v2.getLineForVertical(v1), ((float)v0));
        Object[] v0_1 = arg4.getSpans(v0, v0, e.class);
        e v1_1 = null;
        if(v0_1.length > 0) {
            v0_2 = v0_1[0];
        }
        else {
            v0_2 = v1_1;
        }

        return ((e)v0_2);
    }

    public final boolean onTouchEvent(TextView arg6, Spannable arg7, MotionEvent arg8) {
        e v4 = null;
        if(arg8.getAction() == 0) {
            this.a = d.a(arg6, arg7, arg8);
            if(this.a != null) {
                this.a.a = true;
                Selection.setSelection(arg7, arg7.getSpanStart(this.a), arg7.getSpanEnd(this.a));
            }
        }
        else if(arg8.getAction() == 2) {
            e v0 = d.a(arg6, arg7, arg8);
            if(this.a != null && v0 != this.a) {
                this.a.a = false;
                this.a = v4;
                Selection.removeSelection(arg7);
            }
        }
        else {
            if(this.a != null) {
                this.a.a = false;
                super.onTouchEvent(arg6, arg7, arg8);
            }

            this.a = v4;
            Selection.removeSelection(arg7);
        }

        return true;
    }
}

